<?php include "include/function_library.php"; ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "html/header.html"; ?>

</head>
<body class="tcuk home">

	<div id="wp">
	
		<?php  include "html/menu.html"; ?>
		
		<!-- CONTENT STARTS-->
		<div id="ct"> 	
			
			<?php 
			if(post("company_submit")) {
				$company_name 		= post("company_name");
				$company_phone 		= post("company_phone");
				$company_tax 		= post("company_tax");
				
				$address_city 		= post("address_city");
				$address_district 	= post("address_district");
				$address_detail		= post("address_detail");
				
				$link = connect();
				$add_address_query = "INSERT INTO address (city, district, detail) VALUES ('$address_city', '$address_district', '$address_detail')";
				
				$result_address = mysql_query($add_address_query, $link) or die("Sql Error! " . mysql_error());
				$last_added_address_id = mysql_insert_id();
				
				$query = "INSERT INTO organizer_company (name, phone, tax_number, address_id) 
						  VALUES ('$company_name', '$company_phone', '$company_tax', '$last_added_address_id')";
				$result = $result_address && (mysql_query($query, $link) or die("Sql Error! " . mysql_error()));
				mysql_close($link);
				
				if($result) {
					echo "<div class='alert success'>Company Saved Successfully! You can <a href='signup_company_form.php'>add users</a> to your company.</div>";
				} else {
					echo "<div class='alert error'>Error! Could Not Save! There is(are) error(s) in the form!</div>";
				}
			}
			?>
			<br/><h2>Add Organizer Company</h2>
			<form action="<?php echo curPageURL(); ?>" method="post">
			<ul id="signup_form" style="width: 50%; margin-left: auto; margin-right: auto; margin-top: 30px; list-style: none;">
				<li style="border: none;">
					<label>Name </label>
					<input type="text" id="company_name" name="company_name" value="" placeholder="Company name.." style="width: 250px;"/>
				</li>
				<li>
					<label>Phone </label>
					<input type="text" id="company_phone" name="company_phone" value="" placeholder="Company phone.." style="width: 250px;"/>
				</li>
				<li>
					<label>Tax Number </label>
					<input type="number" id="company_tax" name="company_tax" value="" placeholder="Company tax number.." style="width: 250px;"/>
				</li>
				<li>
					<label>City </label>
					<input type="text" id="address_city" name="address_city" value="" placeholder="Company City.." style="width: 250px;"/>
				</li>
				<li>
					<label>District </label>
					<input type="text" id="address_district" name="address_district" value="" placeholder="Company District.." style="width: 250px;"/>
				</li>
				<li>
					<label>Address Detail </label>
					<textarea rows="10" id="address_detail" name="address_detail" placeholder="Address Detail.." style="width: 250px;"></textarea>
				</li>
				<li>
					<input type="submit" id="company_submit" name="company_submit" value="Save" style="width: 90px; height:30px; margin-left: 80px;"/>
				</li>
			</ul>
			</form>
		
		</div> 	
		<!-- CONTENT ENDS-->		
		
		<?php include "html/footer.html"; ?>
		
	</div>
	
</body>
</html>